﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace UMLSynthesizer.Tasks.View.Converters
{
    /// <summary>
    /// It's the converter for the source code file extensions
    /// </summary>
    internal class FileExtensionConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string text = "";
            foreach (var ext in value as IEnumerable<string>)
                text += (text.Length == 0 ? ext : ", " + ext);
            return text;
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return from ext in (value as string).Split(new char[] { ',' })
                   let trimExt = ext.Trim()
                   where trimExt.Length > 0
                   select (trimExt[0] == '.' ? "" : ".") + trimExt;
        }
    }
}
